package com.erdos.core.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.erdos.common.web.BaseAction;
import com.erdos.common.web.LoginUtil;
import com.erdos.core.entity.RefTable;
import com.erdos.core.service.RefTableDetailService;
import com.erdos.core.service.RefTableService;

public class RefTableAction extends BaseAction<RefTable> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2189654934914675907L;
	private static final Log logger = LogFactory.getLog(RefTableAction.class);
	private RefTableService refTableService;
	private RefTableDetailService refTableDetailService;
	
	private String refreshDivID ;
	
	
	
	public String save()
	{
		logger.debug("save RefTable start!");
		HttpServletRequest request = ServletActionContext.getRequest();
		if (getSid() == null) {//insert
			logger.debug("Create RefTable");
			entity.setCreatedBy(LoginUtil.getUpcUserPin());
			entity.setCreatedDt(new Date()) ;
			getBaseService().insert(entity);
			request.setAttribute("method", "insert");
			saveBizMessage(getText("tips.insert.success",new String[] { String.valueOf(entity.getSid()) }));
		} else {//update
			logger.debug("Update RefTable");
			entity.setUpdatedBy(LoginUtil.getUpcUserPin());
			entity.setUpdatedDt(new Date()) ;
			getBaseService().update(entity);
			request.setAttribute("method", "update");
			saveBizMessage(getText("tips.update.success", new String[] { String.valueOf(entity.getSid()) }));
		}
		logger.debug("save RefTable end!");
		return SUCCESS;
	}
	
	public String delete() throws Exception {
		logger.debug("delete RefTable");
		HttpServletRequest request = ServletActionContext.getRequest();
		String sid = request.getParameter("sid");
		int deleteResult = getRefTableService().deleteCascadeDetail(sid) ;
		request.setAttribute("method", "delete");
		saveBizMessage(getText("tips.delete.success", new String[] { String.valueOf(deleteResult) }));
		logger.debug("delete RefTable end..");
		return SUCCESS;
	}
	
	public RefTableService getRefTableService() {
		return refTableService;
	}
	public void setRefTableService(RefTableService refTableService) {
		this.refTableService = refTableService;
	}
	
	public RefTableDetailService getRefTableDetailService() {
		return refTableDetailService;
	}
	public void setRefTableDetailService(RefTableDetailService refTableDetailService) {
		this.refTableDetailService = refTableDetailService;
	}

	public String getRefreshDivID() {
		return refreshDivID;
	}

	public void setRefreshDivID(String refreshDivID) {
		this.refreshDivID = refreshDivID;
	}
}
